<?php
declare (strict_types = 1);

namespace app\product\model;

/**
 * @mixin \think\Model
 */
class ProductModel extends BaseModel
{
    protected $table = 'tb_products';
    protected $append = ['create_time_str','update_time_str','charged_str'];

    const CHARGED_YES = 1;
    const CHARGED_NO = 0;
    static $CHARGED_STR = [
        self::CHARGED_YES => '是',
        self::CHARGED_NO => '否'
    ];
    public function getChargedStrAttr($value,$data){
        return @self::$CHARGED_STR[$data['charged']];
    }

    public function getCreateTimeStrAttr($value,$data){
        if(empty($data['create_time'])) return 0;
        return date('Y-m-d H:i:s', $data['create_time']);
    }

    public function getUpdateTimeStrAttr($value,$data){
        if(empty($data['update_time'])) return 0;
        return date('Y-m-d H:i:s', $data['update_time']);
    }

    public function getPtimeAttr($value){
        if(empty($value)) return 0;
        return date('Y-m-d', $value);
    }
}
